package com.zdp.service;

import com.zdp.domain.SkillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author sesshomaru
 * @date 2021/7/24 22:32
 */
@Service
public class ProductService {

    @Autowired
    private RestTemplate restTemplate;

    // 根据商品id从缓存中获取商品信息
    public SkillGoods queryByProductId(Long productId) {
        return restTemplate.getForObject("http://product-server/product/" + productId, SkillGoods.class);
    }

    // 当缓存中商品库存为0时，同步修改数据库中的数据
    public void update(SkillGoods skillGoods) {
        ResponseEntity<String> result = restTemplate.postForEntity("http://product-server/product/", skillGoods, String.class);
        System.out.println(result.getBody());
    }
}
